//
//  YMSetView.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/3/29.
//

import SwiftUI
import Moya

struct YMSetView: View {
    @EnvironmentObject var client :YMClient
    @State private var binding = false
    @State private var slierValue = 0.0
    @State private var dateValue  = Date.init(timeIntervalSinceNow: 0)
    @State private var colorValue = Color.red
    @State private var stepValue = 0
    @State private var textValue = ""
    @State private var loginIn   = false
    @State private var animation   = false
    private var padding = EdgeInsets(top: 15, leading: 2, bottom: 15, trailing: 2)
    var body: some View {
        List {
            HStack {
                Text("夜间模式").font(Font.system(size: 17)).foregroundColor(Color.appx000000())
                Spacer()
                Toggle("", isOn: $binding).tint(AppColor)
            }.padding(padding).onChange(of: binding) { newValue in
                YMClient.setNight(newValue)
                client.night = newValue
            }.onAppear {
                binding = client.night
                debugPrint(moya.client.night)
                debugPrint(binding)
            }
            HStack {
                Text("滑块")
                Slider(value: $slierValue) {
                    
                }.padding(padding)
            }
            HStack {
                Text("进度")
                ProgressView(value:slierValue).padding(padding)
            }
            DatePicker("日期", selection: $dateValue).padding(padding)
            ColorPicker("颜色", selection: $colorValue).padding(padding)
            Stepper("分页", value: $stepValue).padding(padding)
            
            HStack {
                Text("请输入").padding(padding)
                TextEditor(text:$textValue)
            }
            HStack{
                NavigationLink {
                    YMAnimationView()
                } label: {
                    Text("动画")
                }.padding(padding)
            }
            if loginIn{
                Section {
                    HStack {
                        Text("登出").padding(padding).onTapGesture {
                            YMUser.deleteUser()
                            loginIn = YMUser.loginIn
                        }
                    }
                }
            }
//            Menu("福建省") {
//                Text("Menu Item 1")
//                /*@START_MENU_TOKEN@*/Text("Menu Item 2")/*@END_MENU_TOKEN@*/
//                /*@START_MENU_TOKEN@*/Text("Menu Item 3")/*@END_MENU_TOKEN@*/
//            }.padding(padding)
//            ControlGroup {
//                /*@START_MENU_TOKEN@*/Text("Menu Item 1")/*@END_MENU_TOKEN@*/
//                /*@START_MENU_TOKEN@*/Text("Menu Item 2")/*@END_MENU_TOKEN@*/
//                /*@START_MENU_TOKEN@*/Text("Menu Item 3")/*@END_MENU_TOKEN@*/
//            }
//            DisclosureGroup("福建省") {
//                /*@START_MENU_TOKEN@*/Text("Menu Item 1")/*@END_MENU_TOKEN@*/
//                /*@START_MENU_TOKEN@*/Text("Menu Item 2")/*@END_MENU_TOKEN@*/
//                /*@START_MENU_TOKEN@*/Text("Menu Item 3")/*@END_MENU_TOKEN@*/
//            }.padding(padding)
        }.listStyle(.insetGrouped).navigationTitle("设置").navigationBarBackButtonHidden(true).navigationBarItems(leading: BaseNavigationBarBackButton()).onAppear {
            loginIn = YMUser.loginIn
        }//.colorScheme(client.night ? .dark : .light)
    }
}

